import { API_LIST } from '../../../Api/Api'

import { commonTableList } from '../Common/common'
import {
    AddDataButton,
    ModDataButton,
    DelDataButton,
    OpenExcelButton,
    OpenSelection,
    OpenTwoRouter,
} from '../Common/options'

import { QualityProblemTypeTree } from '../Common/Conversion'

export const QualityPatrols = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: e => [
            <OpenSelection
                OptionsEvent={OptionsEvent}
                title="批量启用/禁用"
                data={{
                    type: 'SelectionTemplateEnabled',
                    url: 'posSafetyPatrolsUpdateIsEnabled',
                }}
            />,
            <OpenExcelButton
                key="two"
                title="批量导入"
                OptionsEvent={OptionsEvent}
                data={{
                    save: true,
                    submit: true,
                    url: 'getQualityPatrolExcelTemp',
                    pos: 'posQualityPatrolInfo',
                }}
            />,
            <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />,
        ],
        columns: [
            { ...commonTableList.SearchSort, selectType: 'QualityPatrols' },
            commonTableList.uuid,
            commonTableList.isEnabled,
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization, title: '项目名称' },
            {
                dataIndex: 'constructionCompany',
                title: '施工单位',
                valueType: 'input',
                ellipsis: true,
                width: 160,
                hideInSearch: true,
            },
            {
                dataIndex: 'siteResponsiblePerson',
                title: '现场责任人',
                valueType: 'input',
                ellipsis: true,
                width: 160,
            },
            {
                dataIndex: 'inspectionDate',
                title: '巡检日期',
                valueType: 'Date',
                width: 160,
                hideInSearch: true,
            },
            {
                dataIndex: 'inspector',
                title: '巡检人',
                valueType: 'input',
                ellipsis: true,
                width: 160,
            },
            {
                dataIndex: 'issueCount',
                title: '问题数量',
                valueType: 'input',
                ellipsis: true,
                width: 160,
                hideInSearch: true,
            },
            {
                dataIndex: 'rectificationDeadline',
                title: '整改限期',
                valueType: 'Date',
                width: 160,
                hideInSearch: true,
            },
            {
                dataIndex: 'chiefEngineer',
                title: '项目总工',
                valueType: 'input',
                ellipsis: true,
                width: 160,
                hideInSearch: true,
            },
            {
                dataIndex: 'rectificationStatus',
                title: '整改状态',
                valueType: 'select',
                valueEnum: {
                    未整改: '未整改',
                    已整改: '已整改',
                },
                ellipsis: true,
                width: 160,
            },
            {
                dataIndex: 'qualityProblemTypeUuid',
                title: '类别',
                valueType: 'treeSelect',
                fieldProps: {
                    options: await QualityProblemTypeTree(),
                    fieldNames: { label: 'tableName', value: 'uuid' },
                },
                rules: true,
                ellipsis: true,
                width: 250,
            },
            commonTableList.remark,
            commonTableList.BeginSecurityDate,
            commonTableList.EndSecurityDate,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 240,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />,
                        <OpenTwoRouter
                            key="TwoTwo"
                            title="巡检附件"
                            twoTitle="质量巡检附件信息"
                            modal="TableList"
                            OptionsEvent={OptionsEvent}
                            other={{
                                page: 'AttachmentDetails',
                                actionRef,
                                Permission,
                                oneData: record,
                                header: data.columns,
                            }}
                        />,
                        <DelDataButton
                            OptionsEvent={OptionsEvent}
                            key="del"
                            title="删除"
                            url={url}
                            uuid={record.uuid}
                        />,
                    ]
                },
            },
        ],
    }

    return data
}
